package page.transport;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.ListChoice;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;


import app.WebApp;
import entity.Transport;
import dao.TransportDao;
import dao.RouteDao;
import entity.Route;
import dao.BindingDao;
import entity.Binding;
public class TransportPage extends WebPage {

	public TransportPage(final Transport transport) {
		super();
		
		
		final Form<Transport> form = new Form<Transport>("form", new CompoundPropertyModel<Transport>(transport));
		add(form);
		final BindingDao bindingDao = new BindingDao(
				WebApp.DATA_XML_FOLDER);
		final List<String> route = bindingDao.getAllRoute();
		final ListChoice listChoise = new ListChoice("route",route);
		form.add(listChoise);
		form.add(new TextField<String>("time"));
		final List<String> type = Arrays.asList("Autobus","Trum","Trolleybus");
		final ListChoice listType = new ListChoice("type",type);
		form.add(listType);
		form.add(new SubmitLink("save") {
			@Override
			public void onSubmit() {
				super.onSubmit();
				final TransportDao transportDao = new TransportDao(WebApp.DATA_XML_FOLDER);
				if (transport.getId() == null) {
					transportDao.saveNew(transport);
				} else {
					transportDao.update(transport);
				}
				setResponsePage(new TransportListPage());
			}
		});

		form.add(new Link("cancel") {
			@Override
			public void onClick() {
				setResponsePage(new TransportListPage());
			}
		});
	}
}